<template>
    <div>
        <div class="container">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item class="head">
                    <el-button type="primary" @click="serviceAdd">发布服务</el-button>
                </el-breadcrumb-item>
            </el-breadcrumb>

            <div class="handle-box">
                <span>服务项目：</span><el-input v-model="query.name" placeholder="服务项目"  class="handle-input mr10"></el-input>
                <span>服务分类：</span>
                <el-select v-model="query.item" placeholder="请选择" class="mg">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                <span>商家名称</span><el-input v-model="query.phone" placeholder="输入商家名称" class="handle-input mr10"></el-input>
                <p class="mt">
                    <el-button type="primary" @click="handleSearch">筛选</el-button>
                    <el-button type="primary" @click="handleSearch">导出</el-button>
                </p>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="id" label="服务编号" align="center"></el-table-column>
                <el-table-column class="height" prop="category" label="服务项目" align="center"></el-table-column>
                <el-table-column prop="business" label="商家名称" align="center"></el-table-column>
                <el-table-column prop="introduce" label="服务分类" align="center"></el-table-column>
                <el-table-column prop="currentPrice" label="现价(元)" align="center"></el-table-column>
                <el-table-column prop="originPrice" label="原价(元)" align="center"></el-table-column>
                <el-table-column prop="serviceItem" label="服务介绍" align="center"></el-table-column>
                <el-table-column prop="creationDate" label="注册时间" align="center"></el-table-column>
                <el-table-column align="center" label="操作" width="150">
                    <template slot-scope="scope">
                        <el-button
                        size="mini"
                        type="primary"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                        <el-button
                        size="mini"
                        type="primary"
                        @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageNum"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { serve,serveEidt,del } from '../../../api/index';
import service from '../../../utils/request';
export default {
    name: 'basetable',
    data() {
        return {
            options: [{
                value: '选项1',
                label: '黄金糕'
            }, {
                value: '选项2',
                label: '双皮奶'
            }, {
                value: '选项3',
                label: '蚵仔煎'
            }, {
                value: '选项4',
                label: '龙须面'
            }, {
                value: '选项5',
                label: '北京烤鸭'
            }],
            query: {
                item:'',
                categoryId:'',
                business:'',
                pageNum: 1,
                pageSize: 2,
            },
            tableData: [],
            pageTotal: 0,
            form: {},
        };
    },
    created() {
        this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
            serve(this.query).then(res => {
                console.log(res);
                this.tableData = res.data.list;
                this.pageTotal = res.data.total || 50;
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageNum', 1);
            this.getData();
        },
        // 修改
        handleEdit(index, row) {
            console.log(index, row);
            serveEidt({
                businessId:row.businessId,
                categoryId:row.categoryId,
                currentPrice:row.currentPrice,
                id:row.id,
                serviceItem:row.category,
                introduce:'',
                originPrice:'',
            }).then(r=>{
                console.log(r);
            })
        },
        //删除
        handleDelete(index, row) {
            console.log(index, row);
            del({
                id:row.id,
            }).then(r=>{
                console.log(r);
            })
        },
        //添加
        serviceAdd(){
            console.log('添加');
            this.$router.push('/Serviceadd');
        },
        // 保存编辑
        saveEdit() {
            this.editVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
    background-color: rgb(245,245,245);
    padding: 20px 40px;
}
.head{
    margin-bottom: 20px;
    padding :10px 30px;
}
>>>.el-breadcrumb__item:last-child .el-breadcrumb__inner{
    color: white;
}
.handle-select {
    width: 150px;
}
.mg{
    margin-left: 10px;
    margin-right:30px ;
}
>>>.el-table tbody tr{
    height: 100px;
}
.handle-input {
    width: 250px;
    display: inline-block;
    margin-left: 5px;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 40px;
}
.mt{
    margin-top: 20px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
